﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExpertMIS.Brokers;

namespace ExpertMIS.UserControl
{
    public partial class ucLastedQuestionList : System.Web.UI.UserControl
    {
        public string DomainOID
        {
            get;
            set;
        }

        public bool LoadAsDomainQuestion
        {
            get;
            set;
        }

        public string CSS
        {
            get
            {
                return pnLastQuestion.CssClass;
            }
            set
            {
                pnLastQuestion.CssClass = value;
            }
        }

        public bool ShowTitle
        {
            get
            {
                return dlLastedQuestion.ShowHeader;
            }
            set
            {
                dlLastedQuestion.ShowHeader = value;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            RefreshLastQuestions();
        }

        private void RefreshLastQuestions()
        {
            QuestionBroker broker = new QuestionBroker();

            SYS.Common.Broker.EnvironmentBroker envBroker = new SYS.Common.Broker.EnvironmentBroker();

            if (LoadAsDomainQuestion)
            {
                SYS.Common.Broker.EnvironmentEntity variable = envBroker.GetEnvironmentValue(DomainOID + ".lastquestioncount", false) as SYS.Common.Broker.EnvironmentEntity;
                int count = 18;
                if (variable != null)
                {
                    int.TryParse(variable.Value, out count);
                }

                dlLastedQuestion.DataSource = broker.GetDomainLastQuestion(DomainOID, count);
                dlLastedQuestion.DataBind();
            }
            else
            {
                SYS.Common.Broker.EnvironmentEntity variable = envBroker.GetEnvironmentValue("global.lastquestioncount", false) as SYS.Common.Broker.EnvironmentEntity;
                int count = 18;
                if (variable != null)
                {
                    int.TryParse(variable.Value, out count);
                }
                
                dlLastedQuestion.DataSource = broker.GetLastQuestions(count);
                dlLastedQuestion.DataBind();
            }
        }
    }
}